<template>
  <!-- 供应商钻孔列表 -->
  <div class="app-container">
    <!-- 搜索查询 -->
    <div class="form-container">
      <el-form ref="queryForm" :inline="true" label-width="80px" :model="filters">
        <el-form-item label="钻孔名称" prop="name">
          <el-input v-model="filters.name" clearable placeholder="请输入钻孔名称" size="small" />
        </el-form-item>
      </el-form>
    </div>
    <!--操作按钮-->
    <div class="btns-group">
      <el-button v-clickForbidden icon="el-icon-search" size="middle" @click="handleQuery">搜索</el-button>
      <el-button v-clickForbidden icon="el-icon-refresh" size="middle" @click="resetQuery">重置</el-button>
      <el-button v-clickForbidden icon="el-icon-refresh" size="middle" @click="handleConfirm(true)">确认</el-button>
      <el-button v-clickForbidden icon="el-icon-refresh" size="middle" @click="handleConfirm()">拒绝</el-button>
    </div>
    <!-- 表格展示start -->
    <el-table
      ref="multipleTable"
      v-loading="loading"
      :data="tableData"
      :row-style="rowClass"
      style="width: 100%;"
      stripe
      class="table-list"
      :class="highLevelSet===true ? (needTagsView===true ? 'el-body-page-roll-tag-height' : 'el-body-page-roll-height') :
        (needTagsView===true ? 'el-body-page-roll-tag' : 'el-body-page-roll')"
      @selection-change="handleSelectionChange"
      @row-click="rowChecked"
    >
      <el-table-column type="selection" width="38" />
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column
        prop="equipmentNum"
        label="钻孔编号"
        :show-overflow-tooltip="true"
        min-width="150"
        align="center"
      />
      <el-table-column
        prop="name"
        :show-overflow-tooltip="true"
        label="钻孔名称"
        min-width="150"
        align="center"
      />
      <el-table-column label="状态" min-width="100" align="center" :show-overflow-tooltip="true">
        <template slot-scope="{row}">
          <span v-if="row.consentFlag==='0'">同意</span>
          <span v-if="row.consentFlag==='1'">拒绝</span>
          <span v-if="row.consentFlag==='2'">等待中</span>
          <span v-if="row.consentFlag==='3'">转让</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格展示end-->

    <!-- 分页器 -->
    <pagination
      class="pagination-container"
      :total="total"
      :page.sync="filters.pageNum"
      :limit.sync="filters.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { explorationDistributionPerson, explorationDistributionEquipment } from '@/api/common/approvalReminder'
import { mapState } from 'vuex'
export default {
  name: 'DrillHole',
  data() {
    return {
      // 筛选条件
      highLevelSet: false, // 高级设置显示隐藏
      filters: {
        pageNum: 1,
        pageSize: 20,
        name: '' // 钻孔名称
      },
      /* 列表 start*/
      total: 0, // 分页总条数
      single: true, // 非单个禁用
      selectRow: [], // 高亮样式
      multipleSelection: [], // 选中表格行
      loading: false, // 列表加载
      tableData: [] // 表格数据
      /* 列表 end*/
    }
  },
  computed: {
    ...mapState({
      needTagsView: (state) => state.settings.tagsView
    })
  },
  created() {
    console.log(this.$route.query)
    this.getList()
  },
  methods: {
    // 审批
    handleConfirm(isAgree) {
      const status = isAgree ? '0' : '1'
      const { explorationId, proId } = this.$route.query
      switch (this.msgType) {
        case '021': // 钻孔分配人员
          this.approvalReminder(isAgree, explorationDistributionPerson, { proId, explorationId, consentFlag: status })
          break

        case '031': // 钻孔分配设备
          this.approvalReminder(isAgree, explorationDistributionEquipment, { proId, explorationId, consentFlag: status })
          break
      }
    },
    // 审批
    approvalReminder(isAgree, methodName, params) {
      if (isAgree) {
        this.$confirm('是否同意审批?', '提示', {
          confirmButtonText: '同意',
          cancelButtonText: '取消'
        }).then(async() => { // 同意审批
          const { code } = await methodName(params)
          if (code === 200) {
            this.msgSuccess('审批成功')
            this.$router.go(-1)
          }
        }).catch(() => {})
      } else { // 审批被拒绝
        this.$prompt('请输入拒绝理由', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(async({ value }) => {
          await methodName({ ...params, reason: value })
        }).catch(() => {})
      }
    },
    // 返回
    handleReturn() {
      this.$router.go(-1)
    },
    // 获取数据
    async getList() {
      this.loading = true
      this.addTaleData()
      this.loading = false
    },
    // list表格填充空白行
    addTaleData() {
      if (this.tableData.length < this.fristPageSize) {
        const arr = {}
        this.tableData.push(arr)
        this.addTaleData()
      }
    },
    rowChecked(row) {
      const selectData = this.multipleSelection
      if (selectData.length === 1) {
        selectData.forEach((item) => {
          // 判断 如果当前的一行被勾选, 再次点击的时候就会取消选中
          if (item === row) {
            this.$refs.multipleTable.toggleRowSelection(row, false)
          } else {
            this.$refs.multipleTable.toggleRowSelection(row, true)
          }
        })
      } else {
        this.$refs.multipleTable.toggleRowSelection(row, true)
      }
    },
    // 点击表格前面选框时触发的事件
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 高亮样式
    rowClass({ row, rowIndex }) {
      if (this.selectRow.includes(rowIndex)) {
        return { 'background-color': 'rgba(185,221,249,.75)' }
      }
    },
    /* 按钮 Start */
    // 搜索方法
    handleQuery() {
      this.filters.pageNum = 1
      this.getList()
    },
    // 重置搜索
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>

<style scoped lang="scss">
</style>

